//
//  UIViewController+MLThemeManager.m
//  MSHandbook
//
//  Created by molon on 14/11/25.
//  Copyright (c) 2014年 molon. All rights reserved.
//

#import "UIViewController+MLThemeManager.h"
#import "MLThemeManager.h"
#import "MLRuntime.h"

@implementation UIViewController (MLThemeManager)

- (instancetype)__MLThemeManager_hook_init
{
    id object = [self __MLThemeManager_hook_init];
    if (object) {
        //实现了此代理的直接注册进去
        if ([object conformsToProtocol:@protocol(MLThemeManagerDelegate)]) {
            [[MLThemeManager manager]registerDelegate:object];
        }
    }
    return object;
}

- (void)__MLThemeManager_hook_dealloc
{
    if ([self conformsToProtocol:@protocol(MLThemeManagerDelegate)]) {
        [[MLThemeManager manager]unregisterDelegate:(id<MLThemeManagerDelegate>)self];
    }
    [self __MLThemeManager_hook_dealloc];
}

+ (void)load
{
    Swizzle([self class], NSSelectorFromString(@"init"), @selector(__MLThemeManager_hook_init));
    Swizzle([self class], NSSelectorFromString(@"dealloc"), @selector(__MLThemeManager_hook_dealloc));
}


@end
